home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.xml.parser;
-
- import java.io.IOException;
- import java.io.Writer;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.Enumeration;
- import org.w3c.dom.Attr;
- import org.w3c.dom.CDATASection;
- import org.w3c.dom.Comment;
- import org.w3c.dom.DOMException;
- import org.w3c.dom.DOMImplementation;
- import org.w3c.dom.Document;
- import org.w3c.dom.DocumentFragment;
- import org.w3c.dom.DocumentType;
- import org.w3c.dom.Element;
- import org.w3c.dom.Entity;
- import org.w3c.dom.EntityReference;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import org.w3c.dom.ProcessingInstruction;
- import org.w3c.dom.Text;
-
- public class TXDocument extends Parent implements Document {
- static final long serialVersionUID = -7547414605402949958L;
- static transient TXDocument s_instance = null;
- static transient DOMImplementation s_domImpl = null;
- transient MessageDigest messageDigest;
- String defDigestAlgorithm = "MD5";
- TXElement rootElement;
- DTD doctype;
- String standalone;
- String xmlVersion;
- String xmlEncoding;
- boolean isCheckDocument = false;
- boolean checkValidity = false;
- boolean isProcessNamespace = false;
- boolean isCheckNodeLoop = true;
- boolean isAddFixedAttributes = true;
- public String expandedNameSeparator = ":";
-
- public Object clone() {
- return this.cloneNode(true);
- }
-
- public synchronized Node cloneNode(boolean var1) {
- ((Child)this).checkFactory();
-
- TXDocument var2;
- try {
- var2 = (TXDocument)this.getClass().newInstance();
- } catch (InstantiationException var4) {
- throw new LibraryException("TXDocument#cloneNode(): " + var4);
- } catch (IllegalAccessException var5) {
- throw new LibraryException("TXDocument#cloneNode(): " + var5);
- }
-
- ((Child)var2).setFactory(this.getFactory());
- var2.defDigestAlgorithm = "MD5";
- var2.standalone = this.standalone;
- var2.xmlVersion = this.xmlVersion;
- var2.xmlEncoding = this.xmlEncoding;
- var2.isCheckDocument = this.isCheckDocument;
- var2.checkValidity = this.checkValidity;
- var2.isProcessNamespace = this.isProcessNamespace;
- var2.isCheckNodeLoop = this.isCheckNodeLoop;
- var2.isAddFixedAttributes = this.isAddFixedAttributes;
- if (var1) {
- var2.children.ensureCapacity(super.children.getLength());
-
- for(int var3 = 0; var3 < super.children.getLength(); ++var3) {
- ((Parent)var2).appendChild(super.children.item(var3).cloneNode(true));
- }
- }
-
- var2.rootElement = (TXElement)var2.getDocumentElement();
- var2.doctype = var2.getDTD();
- return var2;
- }
-
- public synchronized boolean equals(Node var1, boolean var2) {
- if (!(var1 instanceof TXDocument)) {
- return false;
- } else {
- TXDocument var3 = (TXDocument)var1;
- if (var3.standalone == null && this.standalone == null || var3.standalone != null && var3.standalone.equals(this.standalone)) {
- if (var3.xmlVersion == null && this.xmlVersion == null || var3.xmlVersion != null && var3.xmlVersion.equals(this.xmlVersion)) {
- if (var3.xmlEncoding == null && this.xmlEncoding == null || var3.xmlEncoding != null && var3.xmlEncoding.equals(this.xmlEncoding)) {
- return !var2 || var3.children.equals(super.children, var2);
- } else {
- return false;
- }
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- }
-
- public short getNodeType() {
- return 9;
- }
-
- public String getNodeName() {
- return "#document";
- }
-
- public Element getDocumentElement() {
- return this.rootElement;
- }
-
- void setDocumentElement(Element var1) {
- this.rootElement = (TXElement)var1;
- }
-
- public String getRootName() {
- return this.rootElement == null ? null : this.rootElement.getTagName();
- }
-
- public NodeList getElementsByTagName(String var1) {
- return (NodeList)(this.rootElement != null ? this.rootElement.getElementsByTagName(var1) : TXNodeList.emptyNodeList);
- }
-
- public DocumentType getDoctype() {
- return this.doctype;
- }
-
- public DTD getDTD() {
- return this.doctype;
- }
-
- public boolean isCheckValidity() {
- return this.checkValidity;
- }
-
- protected void resetCheckValidity() {
- this.checkValidity = false;
- if (this.doctype != null) {
- Enumeration var1 = this.doctype.getElementDeclarations();
- if (var1.hasMoreElements()) {
- this.checkValidity = true;
- }
- }
-
- }
-
- public String getStandalone() {
- return this.standalone;
- }
-
- public boolean isStandalone() {
- return this.standalone == null ? false : "yes".equals(this.standalone);
- }
-
- public void setStandalone(String var1) {
- this.standalone = var1;
- if (this.xmlVersion == null) {
- this.xmlVersion = "1.0";
- }
-
- }
-
- public String getVersion() {
- return this.xmlVersion;
- }
-
- public void setVersion(String var1) {
- this.xmlVersion = var1;
- }
-
- public String getEncoding() {
- return this.xmlEncoding;
- }
-
- public void setEncoding(String var1) {
- this.xmlEncoding = var1;
- if (this.xmlVersion == null) {
- this.xmlVersion = "1.0";
- }
-
- }
-
- public void setProcessNamespace(boolean var1) {
- this.isProcessNamespace = var1;
- }
-
- public boolean isProcessNamespace() {
- return this.isProcessNamespace;
- }
-
- protected void realInsert(Node var1, int var2) throws LibraryException {
- super.realInsert(var1, var2);
- if (var1 instanceof DTD) {
- if (this.doctype != null) {
- this.removeChild(this.doctype);
- }
-
- this.doctype = (DTD)var1;
- } else {
- if (var1 instanceof TXElement) {
- if (this.rootElement != null) {
- throw new LibraryException("com.ibm.xml.parser.TXDocument#insert(): Document root Element was set twice.");
- }
-
- this.setDocumentElement((Element)var1);
- }
-
- }
- }
-
- public Node replaceChild(Node var1, Node var2) throws DOMException {
- if (var1.getNodeType() == 1 && this.getDocumentElement() != null && var2.getNodeType() != 1) {
- throw new TXDOMException((short)3, "Root element already exists.");
- } else {
- super.replaceChild(var1, var2);
- if (var1.getNodeType() != 1 && var2.getNodeType() == 1) {
- this.setDocumentElement((Element)null);
- }
-
- if (var1.getNodeType() == 1) {
- this.setDocumentElement((Element)var1);
- }
-
- return var2;
- }
- }
-
- public Node removeChild(Node var1) throws DOMException {
- super.removeChild(var1);
- if (var1 == this.getDocumentElement()) {
- this.setDocumentElement((Element)null);
- } else if (var1 == this.getDoctype()) {
- this.doctype = null;
- }
-
- return var1;
- }
-
- public void printWithFormat(Writer var1) throws IOException, LibraryException {
- this.printWithFormat(var1, (String)null, 2);
- }
-
- public void printWithFormat(Writer var1, String var2) throws IOException, LibraryException {
- this.printWithFormat(var1, var2, 2);
- }
-
- public void printWithFormat(Writer var1, String var2, int var3) throws IOException, LibraryException {
- try {
- FormatPrintVisitor var4 = new FormatPrintVisitor(var1, var2, var3);
- (new NonRecursivePreorderTreeTraversal(var4)).traverse(this);
- } catch (IOException var5) {
- throw var5;
- } catch (Exception var6) {
- throw new LibraryException("com.ibm.xml.parser.TXDocument#printWithFormat(): Unexpected Exception: " + ((Throwable)var6).toString());
- }
- }
-
- public void setPrintInternalDTD(boolean var1) {
- if (this.doctype != null) {
- this.doctype.setPrintInternalDTD(var1);
- }
-
- }
-
- public String getText() {
- return this.rootElement != null ? this.rootElement.getText() : "";
- }
-
- public DOMImplementation getImplementation() {
- if (s_domImpl == null) {
- s_domImpl = new 1();
- }
-
- return s_domImpl;
- }
-
- public void acceptPre(Visitor var1) throws Exception {
- var1.visitDocumentPre(this);
- }
-
- public void acceptPost(Visitor var1) throws Exception {
- var1.visitDocumentPost(this);
- }
-
- public Document getOwnerDocument() {
- return null;
- }
-
- public TXDocument getFactory() {
- return this;
- }
-
- public static TXDocument getInstance() {
- if (s_instance == null) {
- s_instance = new TXDocument();
- }
-
- return s_instance;
- }
-
- public Element createElement(String var1) throws DOMException {
- if (!Util.checkName(var1)) {
- throw new TXDOMException((short)5, "Invalid name: " + var1);
- } else {
- TXElement var2 = new TXElement(var1);
- ((Child)var2).setFactory(this);
- return var2;
- }
- }
-
- public Attr createAttribute(String var1) throws DOMException {
- if (!Util.checkName(var1)) {
- throw new TXDOMException((short)5, "Invalid name: " + var1);
- } else {
- TXAttribute var2 = new TXAttribute(var1, (String)null);
- ((Child)var2).setFactory(this);
- return var2;
- }
- }
-
- TXText createAttributeValue(String var1) {
- return this.createTextNode(var1, false);
- }
-
- public Text createTextNode(String var1) {
- return this.createTextNode(var1, false);
- }
-
- public TXText createTextNode(String var1, boolean var2) {
- TXText var3 = new TXText(var1);
- ((Child)var3).setFactory(this);
- var3.setIsIgnorableWhitespace(var2);
- return var3;
- }
-
- public TXText createTextNode(char[] var1, int var2, int var3, boolean var4) {
- TXText var5 = new TXText(new String(var1, var2, var3));
- ((Child)var5).setFactory(this);
- var5.setIsIgnorableWhitespace(var4);
- return var5;
- }
-
- public CDATASection createCDATASection(String var1) throws DOMException {
- TXCDATASection var2 = new TXCDATASection(var1);
- ((Child)var2).setFactory(this);
- return var2;
- }
-
- public Comment createComment(String var1) {
- TXComment var2 = new TXComment(var1);
- ((Child)var2).setFactory(this);
- return var2;
- }
-
- public ProcessingInstruction createProcessingInstruction(String var1, String var2) throws DOMException {
- if (!Util.checkName(var1)) {
- throw new TXDOMException((short)5, "Invalid PI target name: " + var1);
- } else {
- TXPI var3 = new TXPI(var1, var2);
- ((Child)var3).setFactory(this);
- return var3;
- }
- }
-
- public StylesheetPI createStylesheetPI(String var1, String var2, String var3, String var4, String var5) {
- StylesheetPI var6 = new StylesheetPI(var1, var2, var3, var4, var5);
- ((Child)var6).setFactory(this);
- return var6;
- }
-
- public DTD createDTD() {
- DTD var1 = new DTD();
- ((Child)var1).setFactory(this);
- return var1;
- }
-
- public DTD createDTD(String var1, ExternalID var2) {
- DTD var3 = new DTD(var1, var2);
- ((Child)var3).setFactory(this);
- return var3;
- }
-
- public ElementDecl createElementDecl(String var1, ContentModel var2) {
- ElementDecl var3 = new ElementDecl(var1, var2);
- ((Child)var3).setFactory(this);
- return var3;
- }
-
- public ContentModel createContentModel(int var1) {
- ContentModel var2 = new ContentModel(var1);
- var2.setFactory(this);
- return var2;
- }
-
- public ContentModel createContentModel(CMNode var1) {
- ContentModel var2 = new ContentModel(var1);
- var2.setFactory(this);
- return var2;
- }
-
- public Attlist createAttlist(String var1) {
- Attlist var2 = new Attlist(var1);
- ((Child)var2).setFactory(this);
- return var2;
- }
-
- public AttDef createAttDef(String var1) {
- AttDef var2 = new AttDef(var1);
- ((Child)var2).setFactory(this);
- return var2;
- }
-
- public EntityDecl createEntityDecl(String var1, String var2, boolean var3) {
- EntityDecl var4 = new EntityDecl(var1, var2, var3);
- ((Child)var4).setFactory(this);
- return var4;
- }
-
- public EntityDecl createEntityDecl(String var1, ExternalID var2, boolean var3, String var4) {
- EntityDecl var5 = new EntityDecl(var1, var2, var3, var4);
- ((Child)var5).setFactory(this);
- return var5;
- }
-
- public TXNotation createNotation(String var1, ExternalID var2) {
- TXNotation var3 = new TXNotation(var1, var2);
- ((Child)var3).setFactory(this);
- return var3;
- }
-
- public EntityReference createEntityReference(String var1) throws DOMException {
- if (!Util.checkName(var1)) {
- throw new TXDOMException((short)5, "Invalid entity name: " + var1);
- } else {
- GeneralReference var2 = new GeneralReference(var1);
- ((Child)var2).setFactory(this);
- return var2;
- }
- }
-
- public DocumentFragment createDocumentFragment() {
- TXDocumentFragment var1 = new TXDocumentFragment();
- ((Child)var1).setFactory(this);
- return var1;
- }
-
- public Entity createEntity() {
- return null;
- }
-
- public MessageDigest createMessageDigest() throws NoSuchAlgorithmException {
- if (this.messageDigest == null) {
- this.messageDigest = MessageDigest.getInstance(this.defDigestAlgorithm);
- } else {
- this.messageDigest.reset();
- }
-
- return this.messageDigest;
- }
-
- public void setDigestAlgorithm(String var1) {
- if (!this.defDigestAlgorithm.equals(var1)) {
- this.defDigestAlgorithm = var1;
- this.messageDigest = null;
- }
-
- }
-
- protected void checkChildType(Node var1) throws DOMException {
- switch (var1.getNodeType()) {
- case 1:
- case 3:
- case 7:
- case 8:
- case 10:
- case 23:
- return;
- default:
- throw new TXDOMException((short)3, "Specified node type (" + var1.getNodeType() + ") can't be a child of Document.");
- }
- }
-
- public boolean isCheckOwnerDocument() {
- return this.isCheckDocument;
- }
-
- public void setCheckOwnerDocument(boolean var1) {
- this.isCheckDocument = var1;
- }
-
- public boolean isCheckNodeLoop() {
- return this.isCheckNodeLoop;
- }
-
- public void setCheckNodeLoop(boolean var1) {
- this.isCheckNodeLoop = var1;
- }
-
- public boolean isAddFixedAttributes() {
- return this.isAddFixedAttributes;
- }
-
- public void setAddFixedAttributes(boolean var1) {
- this.isAddFixedAttributes = var1;
- }
- }
-